using System;
using UnityEngine;

public static class Extension
{
	public static void Play(this Animation[] animations)
	{
		foreach (Animation animation in animations)
		{
			animation.Play();
		}
	}

	public static void Play(this Animation[] animations, string name)
	{
		foreach (Animation animation in animations)
		{
			animation.Play(name);
		}
	}

	public static void PlayQueued(this Animation[] animations, string name)
	{
		foreach (Animation animation in animations)
		{
			animation.PlayQueued(name);
		}
	}

	public static void Shuffle<T>(this T[] list)
	{
		int num = list.Length;
		System.Random random = new System.Random();
		while (num > 1)
		{
			num--;
			int num2 = random.Next(num + 1);
			T val = list[num2];
			list[num2] = list[num];
			list[num] = val;
		}
	}

	public static T[] SubArray<T>(this T[] data, int index, int length)
	{
		T[] array = new T[length];
		Array.Copy(data, index, array, 0, length);
		return array;
	}

	public static int ToInt(this bool value)
	{
		return value ? 1 : 0;
	}

	public static float Abs(this float value)
	{
		return (!(value < 0f)) ? value : (0f - value);
	}

	public static bool Contains(this int mask, int layer)
	{
		return mask == (mask | (1 << layer));
	}

	public static int GetBit(this int value, int bit)
	{
		return (value >> bit) & 1;
	}

	public static int GetBit(this int value, int bit, int amount)
	{
		int num = 0;
		for (int i = 0; i < amount; i++)
		{
			num |= value.GetBit(bit + i) << i;
		}
		return num;
	}

	public static int SetBit(this int value, int bit, int newValue)
	{
		return (newValue != 0) ? value.SetBit1(bit) : value.SetBit0(bit);
	}

	public static int SetBit(this int value, int bit, int newValue, int amount)
	{
		for (int i = 0; i < amount; i++)
		{
			value = value.SetBit(bit + i, newValue);
		}
		return value;
	}

	public static int SetBit0(this int value, int bit)
	{
		return value & ~(1 << bit);
	}

	public static int SetBit1(this int value, int bit)
	{
		return value | (1 << bit);
	}

	public static bool ToBool(this int value)
	{
		return value != 0;
	}

	public static string ReplaceAt(this string input, int index, char newChar)
	{
		char[] array = input.ToCharArray();
		array[index] = newChar;
		return new string(array);
	}

	public static void ChildrenDestroy(this Transform transform)
	{
		for (int num = transform.childCount - 1; num >= 0; num--)
		{
			Transform child = transform.GetChild(num);
			UnityEngine.Object.Destroy(child.gameObject);
			child.SetParent(null);
		}
	}

	public static Transform[] GetAllChildren(this Transform transform)
	{
		return transform.GetChildren(transform.childCount);
	}

	public static Transform[] GetChildren(this Transform transform, int amount)
	{
		Transform[] array = new Transform[amount];
		for (int i = 0; i < amount; i++)
		{
			array[i] = transform.GetChild(i);
		}
		return array;
	}

	public static Vector2 Ceil(this Vector2 vector2)
	{
		return new Vector2(Mathf.CeilToInt(vector2.x), Mathf.CeilToInt(vector2.y));
	}

	public static Vector2 Floor(this Vector2 vector2)
	{
		return new Vector2(Mathf.FloorToInt(vector2.x), Mathf.FloorToInt(vector2.y));
	}

	public static Vector2 Round(this Vector2 vector2)
	{
		return new Vector2(Mathf.Round(vector2.x), Mathf.Round(vector2.y));
	}

	public static Vector2Int ToVector2Int(this Vector2 vector2)
	{
		return new Vector2Int(Mathf.RoundToInt(vector2.x), Mathf.RoundToInt(vector2.y));
	}

	public static Vector3 ToVector3(this Vector2Int vector2Int)
	{
		return new Vector3(vector2Int.x, vector2Int.y);
	}

	public static Vector3 RemoveZ(this Vector3 vector3)
	{
		vector3.z = 0f;
		return vector3;
	}

	public static Vector3 Round(this Vector3 vector2)
	{
		return new Vector3(Mathf.Round(vector2.x), Mathf.Round(vector2.y));
	}

	public static Vector2 ToVector2(this Vector3 vector3)
	{
		return new Vector2(vector3.x, vector3.y);
	}

	public static Vector2Int ToVector2Int(this Vector3 vector3)
	{
		return new Vector2Int(Mathf.RoundToInt(vector3.x), Mathf.RoundToInt(vector3.y));
	}
}
